package com.github.prontera.controller;

import io.swagger.annotations.ApiOperation;

import java.time.OffsetDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.prontera.ApiVersion;
import com.github.prontera.domain.SysDict;
import com.github.prontera.domain.Tags;
import com.github.prontera.model.response.ObjectDataResponse;
import com.github.prontera.service.SysDictService;
import com.github.prontera.service.TagsService;
import com.github.prontera.util.Page;

/**
 * 技能标签
 * @author Alex
 */
@RestController
@RequestMapping(value = ApiVersion.MANAGE_V1_PREFIX + "/dict", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE }, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public class DictController {

	@Autowired
	private SysDictService sysDictService;

	@ApiOperation(value = "查询标签内容", notes = "查询字典内容")
	@RequestMapping(value = "findDictList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<SysDict>> findTagList(@RequestBody SysDict tag) {
		Page<SysDict>  page = sysDictService.findDictList(tag);
		return new ObjectDataResponse<Page<SysDict>>(page);
	}

	@ApiOperation(value = "查询一级父类", notes = "查询字典内容")
	@RequestMapping(value = "findParentList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<SysDict>> findParentList(@RequestBody SysDict tag) {
		Page<SysDict>  page = sysDictService.findDictList(tag);
		return new ObjectDataResponse<Page<SysDict>>(page);
	}

	@ApiOperation(value = "修改标签内容", notes = "修改标签内容")
	@RequestMapping(value = "updateDict", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> updateTag(@RequestBody SysDict tag) {
		if(tag!=null){
			tag.setUpdateTime(OffsetDateTime.now());
		}
		Integer res = sysDictService.update(tag);
		return new ObjectDataResponse<Integer>(res);
	}

	@ApiOperation(value = "添加标签内容", notes = "添加标签内容")
	@RequestMapping(value = "addDict", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> addTag(@RequestBody SysDict tag) {
		if(tag!=null){
			tag.setClientId(Long.parseLong("0"));
			tag.setCreateTime(OffsetDateTime.now());
			tag.setUpdateTime(OffsetDateTime.now());
		}
		Integer res = sysDictService.insert(tag);
		return new ObjectDataResponse<Integer>(res);
	}

}
